package org.flexlancer.databases
{
	public class AppUsers
	{
		private static const TABLE:String = "appusers";
		
		public static function Add(userid:String,password:String,allowReports:int=0, allowPOS:int=0,allowManage:int=0):void{
			try{
				var insertObj:Object = new Object();
				insertObj.userid = userid;
				insertObj.password = password;
				insertObj.allowreports = allowReports;
				insertObj.allowpos = allowPOS;
				insertObj.allowmanage = allowManage;
				DatabaseManager.Manager.Insert(TABLE,insertObj);
			}catch(err:Error){
				throw err;
			}
		}

		public static function Update(userid:String,password:String,allowReports:int=0, allowPOS:int=0,allowManage:int=0):void{
			try{
				var updateObj:Object = new Object();
				updateObj.password = password;
				updateObj.allowreports = allowReports;
				updateObj.allowpos = allowPOS;
				updateObj.allowmanage = allowManage;
				DatabaseManager.Manager.Update(TABLE,updateObj,"userid LIKE '"+userid+"'");
			}catch(err:Error){
				throw err;
			}
		}

		public static function List(condition:String = ""):Array{
			try{
				return DatabaseManager.Manager.Select(TABLE,null,condition,"userid");
			}catch(err:Error){
				throw err;
			}
			return new Array;
		}
		
		public static function Delete(condition:String = ""):void{
			try{
				DatabaseManager.Manager.Delete(TABLE,condition);
			}catch(err:Error){
				throw err;
			}
		}
	}
}